package 实习刷题.必刷TOP101.Month12.day02;

public class 链表_BM2 {
    public ListNode reverseBetween (ListNode head, int m, int n) {
        // write code here
        ListNode node = new ListNode(-1);
        node.next = head;
        ListNode slow = node;
        ListNode fast = head;
        for (int i = 1; i < m; i++) {
            slow = slow.next;
            fast = fast.next;
        }
        for (int i = m; i < n; i++) {
            ListNode temp = fast.next;
            fast.next = temp.next;
            temp.next = slow.next;
            slow.next = temp;
        }
        return node.next;
    }
}
